<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>应用Vue的计算属性computed</title>
<!--引入Vue库-->
<script src="vue.js"></script>
</head>
<body>
<script>
var vm = new Vue({
  data: { x: 1 },
  computed: {
    // 仅读取
    xDouble: function () {
      return this.x * 2
    },
    // 读取和设置
    xPlus: {
      get: function () {
        return this.x + 2
      },
      set: function (v) {
        this.x = v - 1
      }
    }
  }
})
console.log(vm.xPlus);      // => 3
console.log(vm.xPlus = 4);  // => 4
console.log(vm.x);          // => 3
console.log(vm.xDouble);    // => 6
</script>
</body>
</html>